package cn.lysj.framework.customer.util;

import cn.lysj.framework.common.utils.random.RandomUtil;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ Author ：drj.
 * @ Date  ：Created in 17:41 2018/11/8
 * @ Description:用户昵称表情过滤
 **/

public class ExpressFiler {
    private static Pattern emoji = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]",Pattern.UNICODE_CASE | Pattern . CASE_INSENSITIVE ) ;



    public static String emojiFilter(String source){
        if(source == null){
            source = "";
        }
        Matcher emojiMatcher = emoji.matcher(source);
        if (emojiMatcher.find()){
            source = emojiMatcher.replaceAll("");
            if(source ==  null?true:source.trim().equals("")){
                source = "窝巢用户"+RandomUtil.getRandomNum(6);
            }
        }
        return source;
    }
}
